package cn.monkey.transport.netty.server.codec.protocol.tcp.http.ws;

import cn.monkey.transport.netty.server.codec.protocol.tcp.http.HttpServerProtocolConsumer;
import cn.monkey.transport.netty.utils.ChannelHandlerUtils;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolConfig;
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;

public interface WebsocketServerProtocolConsumer extends HttpServerProtocolConsumer {

    WebSocketServerProtocolConfig webSocketServerProtocolConfig();

    @Override
    default void accept(Channel channel) {
        HttpServerProtocolConsumer.super.accept(channel);
        channel.pipeline()
                .addLast(ChannelHandlerUtils.normalizeName(WebSocketServerProtocolHandler.class), new WebSocketServerProtocolHandler(this.webSocketServerProtocolConfig()));
    }
}
